using System;
using System.Drawing;
//using System.Linq;
using System.Runtime.InteropServices;
//using System.Xml.Linq;
using System.Windows.Forms;

//===================================
//'
	public class frmSplash : System.Windows.Forms.Form
	{
		//'
		#region Windows Form Designer generated code
		public frmSplash()
		{
			//
			// Required for Windows Form Designer support
			// TODO: Add any constructor code after InitializeComponent call
			//
			InitializeComponent();
			//SetStyle(ControlStyles.SupportsTransparentBackColor, True)
		}
		
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
         this.LTitulo = new System.Windows.Forms.Panel();
         this.lblTitulo = new System.Windows.Forms.Label();
         this.SuspendLayout();
         // 
         // LTitulo
         // 
         this.LTitulo.BackColor = System.Drawing.Color.Transparent;
         this.LTitulo.Location = new System.Drawing.Point(347, 12);
         this.LTitulo.Name = "LTitulo";
         this.LTitulo.Size = new System.Drawing.Size(36, 32);
         this.LTitulo.TabIndex = 0;
         this.LTitulo.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LTitulo_MouseDown);
         this.LTitulo.MouseMove += new System.Windows.Forms.MouseEventHandler(this.LTitulo_MouseMove);
         this.LTitulo.MouseUp += new System.Windows.Forms.MouseEventHandler(this.LTitulo_MouseUp);
         // 
         // lblTitulo
         // 
         this.lblTitulo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
         this.lblTitulo.BackColor = System.Drawing.Color.Transparent;
         this.lblTitulo.Font = new System.Drawing.Font("Old English Text MT", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
         this.lblTitulo.Location = new System.Drawing.Point(-41, -67);
         this.lblTitulo.Name = "lblTitulo";
         this.lblTitulo.Size = new System.Drawing.Size(449, 208);
         this.lblTitulo.TabIndex = 3;
         this.lblTitulo.Text = "GesCan";
         this.lblTitulo.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
         this.lblTitulo.Click += new System.EventHandler(this.frmSplash_Click);
         // 
         // frmSplash
         // 
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.BackgroundImage = global::Gescan.Properties.Resources.GesCan;
         this.ClientSize = new System.Drawing.Size(393, 410);
         this.Controls.Add(this.lblTitulo);
         this.Controls.Add(this.LTitulo);
         this.DoubleBuffered = true;
         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
         this.Name = "frmSplash";
         this.ShowIcon = false;
         this.ShowInTaskbar = false;
         this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
         this.Text = "Form1Pelao";
         this.Activated += new System.EventHandler(this.MainForm_Activated);
         this.Deactivate += new System.EventHandler(this.MainForm_Deactivate);
         this.Load += new System.EventHandler(this.frmSplash_Load);
         this.Click += new System.EventHandler(this.frmSplash_Click);
         this.ResumeLayout(false);

		}
		#endregion
		//'
		#region  Variables
		internal System.Windows.Forms.Timer Timer1;
		//'
		#region Variables de Control Grafico
		private Image img;
		private Image result;
		private Rectangle rectangle;
		//
		private System.Windows.Forms.Panel LTitulo;
		public System.Windows.Forms.Button Cerrar;
		private System.Windows.Forms.Panel panel1;
		internal System.Windows.Forms.Label lblTitulo;
		private System.ComponentModel.Container components = null;
		#endregion
		//'
		#endregion
		//'
		private void frmSplash_Click(System.Object sender, System.EventArgs e)
		{
			Close();
		}
		//'
		private void frmSplash_Load(object sender, System.EventArgs e)
		{
			// Inicializacion de variables
			img = BackgroundImage;
			result = new System.Drawing.Bitmap(img.Width, img.Height);
			rectangle = new System.Drawing.Rectangle(0, 0, img.Width, img.Height);
			MuestraImagen(false);
			activo = true;
			//
			//Temporizador
			Timer1 = new Timer();
			Timer1.Tick += new System.EventHandler(Timer1_Tick);
			Timer1.Enabled = true;
			
			Timer1.Interval = 2000;
			Timer1.Start();
			//
			//Control Título
			lblTitulo.Font = new Font(lblTitulo.Font.Name, 1, FontStyle.Regular);
			//1000 = 1 seg
			Tempo = new Timer();
			Tempo.Tick += new System.EventHandler(Tempo_Tick);
			
			Tempo.Interval = 40;
			Tempo.Start();
		}
		//'
		private void Timer1_Tick(System.Object sender, System.EventArgs e)
		{
			Timer1.Stop();
			//clsVariables.frm_Principal.CargarFondoFrmPrincipal()
			Close();
		}
		//'
		#region Form personalizado
		//'
		#region Codigo para Drag Form
		// ==========================================================================
		
		private bool arrastrar;
		private Point pointMD;
		private Point pointFM;
		private int xDelta;
		private int yDelta;
		private bool activo;
		
		private void LTitulo_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			arrastrar = true;
			pointMD = MousePosition;
			pointFM = Location;
			xDelta = pointMD.X - pointFM.X;
			yDelta = pointMD.Y - pointFM.Y;
			
			Opacity = 100; // 0.2
			MuestraImagen(true);
		}
		
		private void LTitulo_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			Point pointNP = new Point();
			if (arrastrar)
			{
				pointNP.X = MousePosition.X - xDelta;
				pointNP.Y = MousePosition.Y - yDelta;
				Location = pointNP;
			}
		}
		
		private void LTitulo_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			arrastrar = false;
			MuestraImagen(false);
		}
		
		public void Cerrar_Click(object sender, System.EventArgs e)
		{
			Close();
		}
		
		// ==========================================================================
		#endregion
		//'
		#region Funciones de Actualizado de Formulario
		private void MainForm_Activated(object sender, System.EventArgs e)
		{
			if (activo == false)
			{
				MuestraImagen(false);
				activo = true;
			}
		}
		
		private void MainForm_Deactivate(object sender, System.EventArgs e)
		{
			Opacity = 0.5;
			activo = false;
		}
		
		private void MuestraImagen(bool mueveForma)
		{
			System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(result);
			
			if (mueveForma)
			{
				graphics.Clear(Color.White);
			}
			else
			{
				Captura.CapturaForm.Control(this);
				graphics.DrawImage(BackgroundImage, rectangle, 0, 0, img.Width, img.Height, System.Drawing.GraphicsUnit.Pixel);
			}
			graphics.DrawImage(img, rectangle, 0, 0, img.Width, img.Height, System.Drawing.GraphicsUnit.Pixel);
			
			graphics.Dispose();
			
			BackgroundImage = result;
			Refresh();
		}
		#endregion
		//'
		#endregion
		//
		#region Control Título
		private Timer Tempo;
		int contador = 0;
		//
		//Private Sub ConsultaArticulos_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		//   Tempo = New Timer
		//   Tempo.Interval = 40 '1000 = 1 seg
		//End Sub
		
		//Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		//   With lblTitulo
		//      .Font = New Font(.Font.Name, 1, FontStyle.Regular)
		//   End With
		//   contador = 0
		//   Tempo.Start()
		//End Sub
		//
		private void Tempo_Tick(System.Object sender, System.EventArgs e)
		{
			contador++;
			if (contador == 12)
			{
				Tempo.Stop();
			}
			else
			{
				//lblTitulo.Size = New System.Drawing.Size(lblTitulo.Width + 1, lblTitulo.Height + 1) 'Para imagenes
				lblTitulo.Font = new Font(lblTitulo.Font.Name, lblTitulo.Font.Size + contador, FontStyle.Regular);
			}
		}
		#endregion
		//
	}
	
	
	#region Form personalizado
	#region NameSpace Captura
	namespace Captura
	{
		//  Capture Module		Capture Utilities
		//  Copyright ©2003-2004 Excellence Foundation		Don@xfnd.org
		//
		//  This product is free software. You can redistribute it and/or modify it under the
		//  terms of the Public Source Distribution License Agreement (PSDLA) as published by
		//  Excellence Foundation.
		//
		//  This product is distributed in the hope it will be instructional and useful, but
		//  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
		//  FITNESS FOR A PARTICULAR PURPOSE. See the PSDLA for more details. You should have
		//  received a copy of the PSDLA with this product. If not, browse
		//  http://www.xfnd.org/licenses/PSDLA.doc.
		public class CapturaForm
		{
			
			/// <summary>
			/// Captures the specified window or part thereof to a bitmap image.
			/// </summary>
			/// <param name="handle">window handle</param>
			/// <param name="r">capture rectangle</param>
			/// <returns>bitmap image of the window</returns>
			public static Bitmap Window(IntPtr handle, Rectangle r)
			{
				return Window(handle, r.X, r.Y, r.Width, r.Height);
			}
			
			
			/// <summary>
			/// Captures the window or part thereof to a bitmap image.
			/// </summary>
			/// <param name="wndHWND">window handle</param>
			/// <param name="x">x location in window</param>
			/// <param name="y">y location in window</param>
			/// <param name="width">width of capture area</param>
			/// <param name="height">height of capture area</param>
			/// <returns>window bitmap</returns>
			public static Bitmap Window(IntPtr wndHWND, int x, int y, int width, int height)
			{
				IntPtr wndHDC = Dll.USER32.GetDC(wndHWND);
				// get context for window
				//	create compatibile capture context and bitmap
				IntPtr capHDC = Dll.GDI32.CreateCompatibleDC(wndHDC);
				IntPtr capBMP = Dll.GDI32.CreateCompatibleBitmap(wndHDC, width, height);
				
				//	make sure bitmap non-zero
				if (capBMP == IntPtr.Zero)
				{
					// if no compatible bitmap
					Dll.USER32.ReleaseDC(wndHWND, wndHDC);
					//   release window context
					Dll.GDI32.DeleteDC(capHDC);
					//   delete capture context
					//   return null bitmap
					return null;
				}
				
				//	select compatible bitmap in compatible context
				//	copy window context to compatible context
				//  select previous bitmap back into compatible context
				IntPtr prvHDC = Dll.GDI32.SelectObject(capHDC, capBMP);
				Dll.GDI32.BitBlt(capHDC, 0, 0, width, height, wndHDC, x, y, Dll.GDI32.SRCCOPY);
				Dll.GDI32.SelectObject(capHDC, prvHDC);
				
				//	create GDI+ bitmap for window
				Bitmap bmp = System.Drawing.Image.FromHbitmap(capBMP);
				
				//	release window and capture resources
				Dll.USER32.ReleaseDC(wndHWND, wndHDC);
				// release window context
				Dll.GDI32.DeleteDC(capHDC);
				// delete capture context
				Dll.GDI32.DeleteObject(capBMP);
				// delete capture bitmap
				//	return bitmap image to user
				return bmp;
				// return bitmap
			}
			
			
			/// <summary>
			/// Captures the specified area of the control or whats underneath
			/// </summary>
			/// <param name="ctl">Control to capture</param>
			/// <param name="client">If true capture only client area else entire control.</param>
			/// <param name="under">If true capture specified area underneath the control else whats on the control.</param>
			/// <returns>bitmap image of the control or whats underneath the control</returns>
			public static void Control(System.Windows.Forms.Form ctl)
			{
				Bitmap bmp;
				// capture bitmap
				Rectangle ctlR;
				// capture area rectangle in control coordinates
				Rectangle scrR;
				// capture area rectangle in screen coordinates
				int m_hDelay = 100;
				
				scrR = ctl.Bounds;
				// get rectangle in parent coordinates
				if (ctl.Parent != null)
				{
					// if parent exists
					scrR = ctl.Parent.RectangleToScreen(scrR);
				}
				// map to screen coordinates
				ctlR = ctl.RectangleToClient(scrR);
				// get rectangle in control coordinates
				//	capture an area under the control
				
				ctl.Opacity = 0;
				System.Threading.Thread.Sleep(m_hDelay);
				
				float oprvV = (float) ctl.Opacity;
				// save control visibility
				if (oprvV > 0)
				{
					// if control visible
					ctl.Opacity = 0;
					ctl.Refresh();
				}
				
				IntPtr desktopHWND = Dll.USER32.GetDesktopWindow();
				// get window handle for desktop
				bmp = Window(desktopHWND, scrR);
				// get bitmap for capture area under control
				if (ctl.Opacity < 1)
				{
					ctl.BackgroundImage = bmp;
					ctl.Refresh();
					System.Threading.Thread.Sleep(m_hDelay);
					ctl.Opacity = 1;
				}
				System.GC.Collect();
			}
			
		}
	}
	#endregion
	
	#region NameSpace DLL
	namespace Dll
	{
		//  Dll Module		Interop Entry Points in various Dlls
		//  Copyright ©2003-2004 Excellence Foundation		Don@xfnd.org
		//
		//  This product is free software. You can redistribute it and/or modify it under the
		//  terms of the Public Source Distribution License Agreement (PSDLA) as published by
		//  Excellence Foundation.
		//
		//  This product is distributed in the hope it will be instructional and useful, but
		//  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
		//  FITNESS FOR A PARTICULAR PURPOSE. See the PSDLA for more details. You should have
		//  received a copy of the PSDLA with this product. If not, browse
		//  http://www.xfnd.org/licenses/PSDLA.doc.
		
		/// <summary>
		/// GDI32 dll access
		/// </summary>
		public class GDI32
		{
			
			public const int SRCCOPY = 13369376;
			
			[DllImport("gdi32.dll", EntryPoint = "DeleteDC")]public static  extern IntPtr DeleteDC(IntPtr hDc);
			
			[DllImport("gdi32.dll", EntryPoint = "DeleteObject")]public static  extern IntPtr DeleteObject(IntPtr hDc);
			
			[DllImport("gdi32.dll", EntryPoint = "BitBlt")]public static  extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int wDest, int hDest, IntPtr hdcSource, int xSrc, int ySrc, int RasterOp);
			
			[DllImport("gdi32.dll", EntryPoint = "CreateCompatibleBitmap")]public static  extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
			
			[DllImport("gdi32.dll", EntryPoint = "CreateCompatibleDC")]public static  extern IntPtr CreateCompatibleDC(IntPtr hdc);
			
			[DllImport("gdi32.dll", EntryPoint = "SelectObject")]public static  extern IntPtr SelectObject(IntPtr hdc, IntPtr bmp);
		}
		// end class GDI32
		/// <summary>
		/// USER32 dll access
		/// </summary>
		public class USER32
		{
			
			public const int SM_CXSCREEN = 0;
			public const int SM_CYSCREEN = 1;
			
			[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]public static  extern IntPtr GetDesktopWindow();
			
			[DllImport("user32.dll", EntryPoint = "GetDC")]public static  extern IntPtr GetDC(IntPtr ptr);
			
			[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]public static  extern int GetSystemMetrics(int abc);
			
			[DllImport("user32.dll", EntryPoint = "GetWindowDC")]public static  extern IntPtr GetWindowDC(int ptr);
			
			[DllImport("user32.dll", EntryPoint = "ReleaseDC")]public static  extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
		}
		// end class USER32
	}
	// end namespace Dll
	#endregion
	#endregion
